<%@ page contentType="text/html; charset=UTF-8" language="java"%>
<%@ taglib prefix="limits" uri="/WEB-INF/tld/limits.tld"%>
<%@ page import="com.hzqy.commons.utils.ConstantUtils" %>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>角色</title>
<link rel="stylesheet" type="text/css"	href="../../static/js/themes/defalut.css">
<link rel="stylesheet" type="text/css"	href="../../static/js/themes/public.css">
<link rel="stylesheet" type="text/css"	href="../../static/js/themes/ddspstyle.css">
<link rel="stylesheet" type="text/css"	href="../../static/js/themes/default/easyui.css">
<link rel="stylesheet" type="text/css"	href="../../static/js/themes/icon.css">
<script type="text/javascript" src="../../static/js/jquery.min.js"></script>
<script type="text/javascript" src="../../static/js/jquery.easyui.min.js"></script>
<script type="text/javascript" src="../../static/js/locale/easyui-lang-zh_CN.js"></script>
<script type="text/javascript" src="../../static/js/index.js"></script>
<%
	int f_catalog_id = 0;
	String para = request.getParameter("f_catalog_id");
	if(para != null)
		f_catalog_id = Integer.valueOf(para);
	String []nonceObj=ConstantUtils.getNonceObject();
%>
<script type="text/javascript">
		var f_catalog_id = <%=f_catalog_id%>;
		var queryParams;
		function EasyuiDatagrid() {
			$("#easyui-datagrid").datagrid({
				url: '../../content/content_bind.do',
				nowrap: true,
				striped: true,
				border: false,
				fit: true,
				rownumbers:true,
				queryParams: getGueryParams(),
				columns: [[
					{field:'ck',checkbox:true},
					{field:'f_cc_id',title:'内容id',align:'center',width:70},
					{field:'f_cc_name',title:'内容名称',align:'center',width:150},
					{field:'f_cc_companyname',title:'对应企业',align:'center',width:150},
					{field:'f_ccc_viewindex',title:'排序值',align:'center',width:50},
					{field:'f_cc_status',title:'状态',align:'center',width:50,
						formatter:function(value,row,index) {
							var status = "未知";
							if(value==1){
								status="上线";
							} else if(value==2||value==16||value==14){
								status="待审核";
							} else if(value==4||value==13||value==15){
								status="审核未通过";
							}else if(value==5){
								status="待转码";
							}else if(value==17){
								status="等待传输";
							}else if(value==18){
								status="传输失败";
							}else if(value==19){
								status="传输中";
							}
							return status;
						}	
					},
					{field:'f_cc_onlinedate',title:'上线时间',align:'center',width:80,
						formatter:function(value,row,index) {
							var str = "";
							if(value!=null)
								str = value.substring(0,10);
							return str;
						}	
					},
					{field:'f_cc_offlinedate',title:'下线时间',align:'center',width:80,
						formatter:function(value,row,index) {
							var str = "";
							if(value!=null)
								str = value.substring(0,10);
							return str;
						}	
					},
					{field:'f_cc_cdate',title:'创建时间',align:'center',width:150},
					{field:'f_cc_udate',title:'修改时间',align:'center',width:150},
					{field:'f_cc_type',title:'操作',align:'center',width:200,
						formatter:function(value,row,index){
							str ="";
							if(getGueryParams().bind_status == 1) { //已分类显示取消分类
								str += '<a class="easyui-linkbutton l-btn l-btn-plain" iconCls="icon-ok" href="javascript:void(0);" plain="true" onclick="unbind(\''+row.f_cc_id+'\');" ><span class="l-btn-left"><span class="l-btn-text icon-remove l-btn-icon-left">取消分类</span></span></a>';
								str += '<a class="easyui-linkbutton l-btn l-btn-plain" iconCls="icon-ok" href="javascript:void(0);" plain="true" onclick="updateIndex(\''+row.f_cc_id+'\');" ><span class="l-btn-left"><span class="l-btn-text icon-edit l-btn-icon-left">修改</span></span></a>';
							} else if (getGueryParams().bind_status == 2) {//未分类显示分类
								str += '<a class="easyui-linkbutton l-btn l-btn-plain" iconCls="icon-ok" href="javascript:void(0);" plain="true" onclick="bind(\''+row.f_cc_id+'\');" ><span class="l-btn-left"><span class="l-btn-text icon-remove l-btn-icon-left">分类</span></span></a>';
							}
					    	return str;
				    	}
					}
				]],
				singleSelect:false,
				pagination:true,
				pageList:[10,20,30,40,50],
				pageSize:10,
				toolbar: '#toolbar',
				
				onExpandRow: function(index,row){
				
				},
				onSelect: function(rowIndex,rowData) {
					
				},
				onUnselect: function(rowIndex,rowData) {
					
				},
				onCheckAll: function(rowIndex,rowData) {
					
				},
				onUncheckAll: function(rowIndex,rowData) {
				
				},
				onLoadSuccess: function(data) {
					if(data.total==-1) {
						$.messager.defaults={ok:"确定",cancel:"取消"};
						$.messager.confirm('提示', '用户尚未登录,请登录', function(r){
						if (r){
						    window.parent.location.href='/login.do';
						    return false;
						}});
					}
				}
			});
		}
	
		function getGueryParams(){
			return {
				f_cc_name:$("#f_cc_name").val(),
				f_cc_status:1,
				f_ccc_catalogid:$("#f_ccc_catalogid").val(),
				f_cc_types:"0,1,2,3,4,5,110",
				bind_status:$("#bind_status").val(),
				f_cc_companyid:$("#f_cc_companyid").val()
			};
		}
		
		$(function(){
			$.ajax({
				url:"../../pms/org_list.do",
				success:function(data) {
					data = JSON.parse(data);
					var str = "";
					for(var i=0;i<data.length;i++) {
						str+='<option value="'+data[i].id+'">'+data[i].name+'</option>';
					}
					$("#f_cc_companyid").append(str);
				}
			});
			$("#f_ccc_catalogid").val(f_catalog_id);
			new EasyuiDatagrid();
			gotoSearch = function(){
				if(getGueryParams().bind_status == 1){
					$("#batchBind").hide();
					$("#batchUnBind").show();
				} else if (getGueryParams().bind_status == 2) {
					$("#batchBind").show();
					$("#batchUnBind").hide();
				}
				$("#easyui-datagrid").datagrid('reload',getGueryParams());
			};
			
			unbind = function(id){
				$.messager.confirm('确定取消分类','确定取消分类么?',function(r){
					if(r){
						app_ajax('../../content/delete_bind.do?f_ccc_contentid='+id+'&f_ccc_catalogid='+f_catalog_id+"&stime=<%=nonceObj[0]%>&sign=<%=nonceObj[1]%>",
						'',
						function(msg){
							if(msg.success) {
								alert("取消分类成功!");
								if (checkAjaxRequestValidity(msg)) {
									gotoSearch($('#easyui-treegrid'));
								}
							} else {
								alert("取消分类异常，请联系管理员");
								if($.isFunction(window.showMessager)){
									window.showMessager(msg.resultTitle,msg.result);
								}
							}
							window.location.reload();
						}
						);
					}
				});
			};
			
			bind = function(id){
				app_ajax('../../content/insert_bind.do?f_ccc_contentid='+id+'&f_ccc_catalogid='+f_catalog_id+"&stime=<%=nonceObj[0]%>&sign=<%=nonceObj[1]%>",
						'',
						function(msg){
							if(msg.success) {
								alert("分类成功!");
								if (checkAjaxRequestValidity(msg)) {
									gotoSearch($('#easyui-treegrid'));
								}
							} else {
								alert(msg.result + 'flag=' + msg.flag);
								if($.isFunction(window.showMessager)){
									window.showMessager(msg.resultTitle,msg.result);
								}
							}
							window.location.reload();
						}
						);
			};
		});
		
		function SubgridTabOnSelect(title,index){
			setTimeout(function(){
				$("#easyui-datagrid").datagrid('fixDetailRowHeight',index);
			},300);
			setTimeout(function(){
				$("#easyui-datagrid").datagrid('fixDetailRowHeight',index);
			},3000);
	    }
		
		function load(){
			$(".datagrid-row-expander datagrid-row-expand").attr("display","none"); 
		}
		
		function _resert(){
			$("#f_cc_name").val("");
			$("#f_cc_status").val("");
		}
		
		function onpress(){
			var event=arguments.callee.caller.arguments[0]||window.event;//消除浏览器差异
	   		  	if (event.keyCode == 13){  
	      			gotoSearch($('#easyui-treegrid'));
	    		}
		}
		
		function updateIndex(id) {
			openDialog($('#dlg'),'bind_updateIndex.jsp?f_ccc_catalogid='+f_catalog_id+'&f_ccc_contentid='+id);
		}
		
		function batchBind() {
			var selections = $('#easyui-datagrid').datagrid('getSelections');//返回所有被选中的行
			if(selections.length==0) {
				alert("请至少选择一行数据");
				return false;
			}
			var ids=[];
			for(var i=0;i<selections.length;i++) {
				var id = selections[i].f_cc_id;
				ids.push(id);
			}
			$.ajax({
				url:"../../content/batch_bind.do?ids="+ids+"&f_ccc_catalogid="+f_catalog_id+"&stime=<%=nonceObj[0]%>&sign=<%=nonceObj[1]%>",
				success:function(msg){
					msg = JSON.parse(msg);
					if(msg.success) {
						alert("批量分类成功!");
						if (checkAjaxRequestValidity(msg)) {
							gotoSearch($('#easyui-treegrid'));
						}
					} else {
						alert("批量分类异常，请联系管理员");
						if($.isFunction(window.showMessager)){
							window.showMessager(msg.resultTitle,msg.result);
						}
					}
					window.location.reload();
				}
			});
		}
		function batchUnBind() {
			var selections = $('#easyui-datagrid').datagrid('getSelections');//返回所有被选中的行
			if(selections.length==0) {
				alert("请至少选择一行数据");
				return false;
			}
			var ids=[];
			for(var i=0;i<selections.length;i++) {
				var id = selections[i].f_cc_id;
				ids.push(id);
			}
			$.ajax({
				url:"../../content/batch_unbind.do?ids="+ids+"&f_ccc_catalogid="+f_catalog_id+"&stime=<%=nonceObj[0]%>&sign=<%=nonceObj[1]%>",
				success:function(msg){
					msg = JSON.parse(msg);
					if(msg.success) {
						alert("批量取消分类成功!");
						if (checkAjaxRequestValidity(msg)) {
							gotoSearch($('#easyui-treegrid'));
						}
					} else {
						alert("批量取消分类异常，请联系管理员");
						if($.isFunction(window.showMessager)){
							window.showMessager(msg.resultTitle,msg.result);
						}
					}
					window.location.reload();
				}
			});
		}
		function bindOrg() {
			openDialog($('#org_list'),'../behavior_control/org_update.jsp?idField=f_cc_companyid&nameField=f_cc_company_name');
		}
		function resert(){
			$("#f_cc_company_name").val("");
			$("#f_cc_companyid").val("");
		}
	</script>
</head>
<body onload="load();">
	<table id="easyui-datagrid" title="已分类列表"></table>
	<div id="toolbar" class="easyui_datagrid_toolbar" style="">
		<div class="easyuiSearch">
			<form onsubmit="return false;" method="post">
				<input type="hidden" id="f_ccc_catalogid" name="f_ccc_catalogid" value="" />
				<table cellspacing="0" cellpadding="0" width="90%">
					<tr>
						<td align="right" width="5%">内容名称：</td>
						<td align="left" width="15%">
							<input name="f_cc_name"	id="f_cc_name" style="width: 150px;" onkeydown="onpress();" />
						</td>
						<td align="right" width="5%">企业选择:</td>
						<td align="left" width="25%" colspan="2">
							<input name="f_cc_company_name" id="f_cc_company_name" readonly="readonly"	style="width: 150px;" value="" class="yl_inp yw_name" />
							<input name="f_cc_companyid" id="f_cc_companyid" type="hidden" value="" />  
							<input name="status" id="status" type="hidden" value="nochange" />  
							<!-- <select id="f_cc_companyid" name="f_cc_companyid" style="width: 150px;">
							</select> -->
							<!-- <span id="f_cc_companyid_tip" class="tip"></span> -->
							<a id="12" class="easyui-linkbutton" data-options="iconCls:'icon-ok'" href="javascript:void(0);" onclick="resert()">空选</a>
							<a id="12" class="easyui-linkbutton" data-options="iconCls:'icon-ok'" href="javascript:void(0);"
								onclick="bindOrg();">选择</a>
						</td>
						
					</tr>
					<tr>
						<td align="right" width="10%">分类状态:</td>
						<td align="left" width="25%">
							<select id="bind_status" name="bind__status">
									<option value="1" selected="selected">已分类</option>
									<option value="2">未分类</option>
							</select>
						</td>
						<td align="left" width="15%">
								<a href="javascript:void(0);" class="easyui-linkbutton" data-options="iconCls:'icon-search', plain:true" onclick="gotoSearch($('#easyui-datagrid'))">查询</a>
						</td>
						<td align="left" width="15%">
							<div id="batchBind" style="display:none;"><a href="javascript:void(0);" class="easyui-linkbutton" data-options="iconCls:'icon-add', plain:true" onclick="batchBind()">批量分类</a></div>
							<div id="batchUnBind" style="display:block;"><a href="javascript:void(0);" class="easyui-linkbutton" data-options="iconCls:'icon-add', plain:true" onclick="batchUnBind()">批量取消分类</a></div>	
						</td>
						<td align="right" width="10%"></td>
					</tr>
				</table>
			</form>
		</div>
		<div style="margin-bottom: 5px">
			<!-- <a href="javascript:void(0)" class="easyui-linkbutton" onclick="delete();" iconCls="icon-cut" plain="true">删除</a>  -->
		</div>
	</div>
	<div id="dlg" class="easyui-dialog"
		style="width: 600px; height: 470px; padding-top: 0px;"
		data-options="title:'内容管理', iconCls:'icon-save',modal:true,closed:true,buttons:'#dlg_buttons'">
		<iframe scrolling="auto" frameborder="0"
			style="width: 100%; height: 99%;"></iframe>
	</div>
	<div id="org_list" class="easyui-dialog"
		style="width: 800px; height: 500px; padding-top: 0px;"
		data-options="title:'客户选择', iconCls:'icon-save',modal:true,closed:true,buttons:'#dlg_buttons'">
		<iframe scrolling="auto" frameborder="0"
			style="width: 100%; height: 99%;"></iframe>
	</div>
</body>
</html>